<?php
class App_EditController extends Zend_Controller_Action
{
	
	private $pulpit;
	
   	public function init(){
      $this->request = $this->getRequest();
      $this->formData = $this->request->getPost();
      $this->pulpit = new App_Model_Pulpit();

   	}
   	public function indexAction(){

   	}
   //-------------------------------PRIVATE BLOCK ----------------------------------------------------------
   	public function getmotywHTML(){
		$p=$this->pulpit->getPulpitCss();
	   
	   	$html='';
	   	$html.='<br />W tej sekcji możesz ustawić kolorystyke podstawowych elementów strony takie jak :'
	   	.'tło graficzne,kolory sekcji czy kolor czcionki ...<br /><br /><br />Tło <hr>';
	   	$html .='<form id="motform"><table>' ;
	   	 
	   	$html .='<tr><td># <input type="text" name="tlo_strony_kolor" value="'.$p['tlo_strony_kolor'].'"> Kolor strony </td><td></td></tr>';
	   	$html .='<tr><td># <input type="text" name="tlo_naglowka" value="'.$p['tlo_naglowka'].'"> Kolor sekcji nagłówek </td><td><input type="checkbox" '.  (  $p['tlo_naglowka']=='transparent'?("checked='checked'" ):('') ).' name="t_tlo_naglowka"> Transparent </td></tr>';
	   	$html .='<tr><td># <input type="text" name="tlo_ciala" value="'.$p['tlo_ciala'].'"> Kolor sekcji ciała </td><td><input type="checkbox" '.  (  $p['tlo_ciala']=='transparent'?("checked='checked'" ):('') ).' name="t_tlo_ciala"> Transparent </td></tr>';
	   	$html .='<tr><td># <input type="text" name="tlo_stopki" value="'.$p['tlo_stopki'].'"> Kolor sekcji stopki </td><td><input type="checkbox" '.  (  $p['tlo_stopki']=='transparent'?("checked='checked'" ):('') ).' name="t_tlo_stopki"> Transparent </td></tr>';
	   	$html .='<tr><td># <input type="text" name="tlo_strony_url" value="'.$p['tlo_strony_url'].'"> Tło graficzne URL </td><td></td></tr>';
	   	 
	   	$html .='</table>';
	   	$html .='<br /><br />Czcionka <hr>';
	   	$html .='<table>';
	   	$html .='<tr><td># <input type="text" name="kolor_tresci" value="'.$p['kolor_tresci'].'"> Kolor czcionki </td><td></td></tr>';
	   	$html .='</table>';
	   	 
	   	$html .='<input class="formbtn" type="button" value=" zatwierdz " id="zatwierdz_mot" >';
	   	$html .='</form>';
	   	 
	   	return $html;
   	 
   }
   
   //---------------------------------------------------------------------------------------------------------
   	public function motywAction(){
		$this->_helper->viewRenderer->setNoRender(true);
		$this->_helper->layout->disableLayout();
   		//echo print_r($this->formData);
   		
   		$data =$this->formData;
   		
   		if(isset($data['t_tlo_naglowka'])){
   			$data['tlo_naglowka']='';
   		}
   		if(isset($data['t_tlo_ciala'])){
   			$data['tlo_ciala']='';
   		}
   		if(isset($data['t_tlo_stopki'])){
   			$data['tlo_stopki']='';
   		}
   		unset($data['t_tlo_ciala']);
   		unset($data['t_tlo_naglowka']);
   		unset($data['t_tlo_stopki']);
   		$this->pulpit->setPulpitCss($data);
   		
   		if($data['tlo_naglowka']==''){
   			$data['tlo_naglowka']='transparent';
   		}
   		
   		if($data['tlo_ciala']==''){
   			$data['tlo_ciala']='transparent';
   		}
   		
   		if($data['tlo_stopki']==''){
   			$data['tlo_stopki']='transparent';
   		}
   		
   		
   		echo json_encode($data);
   	
   }
   	public function getmotAction(){
   		$this->_helper->viewRenderer->setNoRender(true);
   		$this->_helper->layout->disableLayout();
   		$p=$this->pulpit->getPulpitCss();
   			  		
   		$html='';
   		$html.='<br />W tej sekcji możesz ustawić kolorystyke podstawowych elementów strony takie jak :'
   		.'tło graficzne,kolory sekcji czy kolor czcionki ...<br /><br /><br />Tło <hr>';
   		$html .='<form id="motform"><table>' ;
   		
   		$html .='<tr><td># <input type="text" name="tlo_strony_kolor" value="'.$p['tlo_strony_kolor'].'"> Kolor strony </td><td></td></tr>';
   		$html .='<tr><td># <input type="text" name="tlo_naglowka" value="'.$p['tlo_naglowka'].'"> Kolor sekcji nagłówek </td><td><input type="checkbox" '.  (  $p['tlo_naglowka']=='transparent'?("checked='checked'" ):('') ).' name="t_tlo_naglowka"> Transparent </td></tr>';
   		$html .='<tr><td># <input type="text" name="tlo_ciala" value="'.$p['tlo_ciala'].'"> Kolor sekcji ciała </td><td><input type="checkbox" '.  (  $p['tlo_ciala']=='transparent'?("checked='checked'" ):('') ).' name="t_tlo_ciala"> Transparent </td></tr>';
   		$html .='<tr><td># <input type="text" name="tlo_stopki" value="'.$p['tlo_stopki'].'"> Kolor sekcji stopki </td><td><input type="checkbox" '.  (  $p['tlo_stopki']=='transparent'?("checked='checked'" ):('') ).' name="t_tlo_stopki"> Transparent </td></tr>';
   		$html .='<tr><td># <input type="text" name="tlo_strony_url" value="'.$p['tlo_strony_url'].'"> Tło graficzne URL </td><td></td></tr>';
   		
   		$html .='</table>';
   		$html .='<br /><br />Czcionka <hr>';
   		$html .='<table>';
   		$html .='<tr><td># <input type="text" name="kolor_tresci" value="'.$p['kolor_tresci'].'"> Kolor czcionki </td><td></td></tr>';
   		$html .='</table>';
   		
   		$html .='<input class="formbtn" type="button" value=" zatwierdz " id="zatwierdz_mot" >';
   		$html .='</form>';
   		
   		echo $html;
   		
   	}
   
	public function editTabDataAction(){
		$this->_helper->viewRenderer->setNoRender(true);
   		$this->_helper->layout->disableLayout();
   		
   		$editPanelTabs = $this->pulpit->getEditPanelHtml();
   		
   		$data=null;
   		$data['motyw']['html'] = $this->getmotywHTML(); 
   		$data['ng']['html'] =$editPanelTabs['ng'];
   		$data['bd']['html'] =$editPanelTabs['bd'];
   		$data['ft']['html'] =$editPanelTabs['ft'];
   		
   	echo json_encode($data);
   	
   	}
   	
   	public function editpanelAction(){
   		$this->_helper->viewRenderer->setNoRender(true);
   		$this->_helper->layout->disableLayout();
   		
   		$forms=null;
   		$forms['forms']['baner'] = $this->pulpit->getBanerFormHtml();
   		
   		echo json_encode($forms);
   	}
   	
   	public function testAction(){
   		$this->_helper->viewRenderer->setNoRender(true);
   		$this->_helper->layout->disableLayout();
   		 
   		$html='<div id="testbtn">test test</div>';
   		
   		$js='<script type="text/javascript">dojo.connect(dojo.byId("testbtn"),"onclick",function(){console.log("dupa");});</script>';
   		
   		
   		echo $html.$js;
   	}
   	
   	public function insertwidgetAction(){
   		$this->_helper->viewRenderer->setNoRender(true);
   		$this->_helper->layout->disableLayout();
   		
   		$wid = new App_Model_Widget();
   		
   		$formData = $this->request->getPost();
   		
   		$status =0;
   		
   		$error=0;
   		$ret=null;
   		echo "<html><body><textarea>";
   		if( ($formData['longtext']=="") && ($formData['kolor']=="") && ($_FILES['banerfile']['name']=="") ) {
   			$ret['ready'] =0;
   			$ret['error'] =-1;
   			$ret['msg']=' Wszystkie pola są puste, wypełnij przynajmniej jedno. ';
   		} else {
   			if($_FILES['banerfile']['type']!=""){
   				if($_FILES['banerfile']['type'] =='image/jpeg' || $_FILES['banerfile']['type'] =='image/png' ){
   					move_uploaded_file($_FILES['banerfile']['tmp_name'],APPLICATION_PATH."/../public/storage/".$_FILES['banerfile']['name']);
   					$status=1;
   				}
   				
   			}
   			if($wid->addWidBaner($formData['longtext'],$formData['kolor'],$_FILES['banerfile']['name']) ==1){
   				$ret['ready'] =1;
   				$ret['error'] =0; 
   				$ret['msg']=' Pomyślnie Dodano Baner ';
   			}else{
   				$ret['ready'] =0;
   				$ret['error'] =-2;
   				$ret['msg']=' Wystapił nie oczekiwany błąd ';
   			}
   		}
   		
   		

		echo json_encode($ret);
		//echo print_r($formData);
		//echo print_r($_FILES);
   		echo "</textarea></body></html>";
   	
   		
   	}
}
